//
//  HRBlackListCell.m
//  Hear
//
//  Created by mac on 2017/4/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRBlackListCell.h"
#import "YYKit.h"
#import "HRCoverImageModel.h"
#import "HRCoverTimeModel.h"
@interface HRBlackListCell ()
@property (nonatomic, strong)UIImageView *iconImageView;
@property (nonatomic, strong)UILabel *nickNamel;
@property (nonatomic, strong)UILabel *timeLabel;
@property (nonatomic, strong)UILabel *numLabel;
@property (nonatomic, strong)UIImageView *sexImageView;
@property (nonatomic, strong)UIButton *attentionButton;

@end

@implementation HRBlackListCell

-(void)setSearchModel:(HRUpdataUserInfoModel *)searchModel{
    
    WeakSelf

    
    if (searchModel.UserPictureName.length <10){
        [HRCoverImageModel OriginImage:[UIImage imageNamed:searchModel.UserPictureName] scaleToSize:CGSizeMake(40, 40) callBackOriginImage:^(UIImage *originImage) {
            weakSelf.iconImageView.image = originImage;
        }];
        self.iconImageView.backgroundColor = [UIColor colorWithHexString:searchModel.UserPictureBackgroundColor];
    }else{
        [self.iconImageView.layer setImageWithURL:[NSURL URLWithString:searchModel.UserPictureName] placeholder:[UIImage imageNamed:@""]];
    }
    
    
    
    self.nickNamel.text = searchModel.UserRemark.length>0?searchModel.UserRemark:searchModel.NickName;
    
    self.numLabel.text = searchModel.UserNo;
    
    if ([searchModel.Sex intValue] == 1){
        self.sexImageView.image = [UIImage imageNamed:@"男"];
    }else{
        self.sexImageView.image = [UIImage imageNamed:@"女"];
    }
    
    if([searchModel.LocalId isEqualToString:@"admin"]){
        self.attentionButton.hidden = YES;
    }else{
        self.attentionButton.hidden = NO;
    }
    
    if ([searchModel.IsFollow intValue]){
        [self.attentionButton setTitle:@"好友" forState:0];
//        self.attentionButton.enabled = NO;
//        self.attentionButton.backgroundColor = [UIColor lightGrayColor];
    }else{
        [self.attentionButton setTitle:@"非好友" forState:0];
//        self.attentionButton.enabled = YES;
    }
    

}


-(void)setFollowListModel:(HRFollowListModel *)followListModel{
    WeakSelf
    
    if (followListModel.UserPictureName.length <10){
        [HRCoverImageModel OriginImage:[UIImage imageNamed:followListModel.UserPictureName] scaleToSize:CGSizeMake(40, 40) callBackOriginImage:^(UIImage *originImage) {
            weakSelf.iconImageView.image = originImage;
        }];
        self.iconImageView.backgroundColor = [UIColor colorWithHexString:followListModel.UserPictureBackgroundColor];
    }else{
        [self.iconImageView.layer setImageWithURL:[NSURL URLWithString:followListModel.UserPictureName] placeholder:[UIImage imageNamed:@""]];
    }
    
    
    self.nickNamel.text = followListModel.UserRemark.length>0?followListModel.UserRemark:followListModel.NickName;
    
    self.timeLabel.text = [HRCoverTimeModel covetTime:followListModel.CreateTime];
    
    self.numLabel.text = followListModel.UserNo;
    
    if ([followListModel.Sex intValue] == 1){
        self.sexImageView.image = [UIImage imageNamed:@"男"];
    }else{
        self.sexImageView.image = [UIImage imageNamed:@"女"];
    }
}

-(void)setBlackModel:(HRBlackListModel *)blackModel{
    _blackModel = blackModel;
    WeakSelf

    
    if (blackModel.UserPictureName.length <10){
        [HRCoverImageModel OriginImage:[UIImage imageNamed:blackModel.UserPictureName] scaleToSize:CGSizeMake(40, 40) callBackOriginImage:^(UIImage *originImage) {
            weakSelf.iconImageView.image = originImage;
        }];
        self.iconImageView.backgroundColor = [UIColor colorWithHexString:blackModel.UserPictureBackgroundColor];
    }else{
        [self.iconImageView.layer setImageWithURL:[NSURL URLWithString:blackModel.UserPictureName] placeholder:[UIImage imageNamed:@""]];
    }
    
    
    

    self.nickNamel.text = blackModel.UserRemark.length>0?blackModel.UserRemark:blackModel.NickName;
    
    self.timeLabel.text = [HRCoverTimeModel covetTime:blackModel.CreateTime];
    
    self.numLabel.text = blackModel.UserNo;
    
    if ([blackModel.Sex intValue] == 1){
        self.sexImageView.image = [UIImage imageNamed:@"男"];
    }else{
        self.sexImageView.image = [UIImage imageNamed:@"女"];
    }
}

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"HRBlackListCell";
    
    HRBlackListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        cell = [[HRBlackListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.iconImageView = [UIImageView new];
        [self addSubview:self.iconImageView];
        self.iconImageView.layer.cornerRadius = 20;
        self.iconImageView.clipsToBounds = YES;
        
        
        self.nickNamel = [UILabel new];
        self.nickNamel.textColor = FirstTextColor;
        self.nickNamel.font = CustomUIFont(13);
        [self addSubview:self.nickNamel];
        
        self.numLabel = [UILabel new];
        self.numLabel.textColor = SecondTextColor;
        self.numLabel.font = CustomUIFont(13);
        [self addSubview:self.numLabel];
        
        
        self.sexImageView = [UIImageView new];
        [self addSubview:self.sexImageView];
        
        self.timeLabel = [UILabel new];
        self.timeLabel.textColor = SecondTextColor;
        self.timeLabel.font = CustomUIFont(12);
        [self addSubview:self.timeLabel];
        self.timeLabel.textAlignment = 2;
        
        self.attentionButton = [UIButton buttonWithType:0];
//        self.attentionButton.backgroundColor = MainColor;
        self.attentionButton.titleLabel.font = CustomUIFont(14);
//        [self.attentionButton addTarget:self action:@selector(attentionClick) forControlEvents:UIControlEventTouchUpInside];
        [self.attentionButton setTitleColor:FirstTextColor forState:0];
        [self addSubview:self.attentionButton];
        self.attentionButton.layer.cornerRadius = 4;
        self.attentionButton.clipsToBounds = YES;
//        self.attentionButton.hidden = YES;
        UILabel *lineLabel = [UILabel new];
        lineLabel.backgroundColor = CustomColor(240, 240, 240, 1);
        [self addSubview:lineLabel];
        
        
        CGFloat pading = 15;
        WeakSelf
        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(weakSelf).offset(pading);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        
        [self.nickNamel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.iconImageView.mas_right).offset(pading);
            make.top.equalTo(weakSelf.iconImageView.mas_top);
            make.size.mas_equalTo(CGSizeMake(140, 20));
        }];
        
        [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.iconImageView.mas_right).offset(pading);
            make.top.equalTo(weakSelf.nickNamel.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(50, 20));
        }];
        
        [self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.numLabel.mas_right);
            make.top.equalTo(weakSelf.nickNamel.mas_bottom).offset(5);
            make.size.mas_equalTo(CGSizeMake(10, 10));
        }];
        
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf).offset(-pading);
            make.centerY.equalTo(weakSelf.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(140, 20));
        }];
        
        [self.attentionButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf).offset(-pading);
            make.centerY.equalTo(weakSelf);
            make.size.mas_equalTo(CGSizeMake(55, 34));
        }];
        
        
        [lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf);
            make.height.mas_equalTo(1);
            make.bottom.equalTo(weakSelf.mas_bottom);
        }];
        
    }
    return self;
}

- (void)attentionClick{
    if (self.attentionBlock){
        self.attentionBlock();
    }
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
